﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyPSDALayer;
using MyPS.Models;

namespace MyPS.Areas.Manage.Controllers
{
    public class TechTypeController : Controller
    {
        MyPSEntities db = new MyPSEntities();
        public ActionResult Index()
        {
            var mode = db.TechTypes.ToList();
            return View(mode);
        }

        public ActionResult Edit(int id = 0)
        {
            var mode = db.TechTypes.Find(id);
            if (mode == null)
            {
                return HttpNotFound();
            }
            return View(db.TechTypes.Find(id));
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(TechType mode)
        {
            if (ModelState.IsValid)
            {
                db.Entry<TechType>(mode).State = System.Data.EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(mode);
        }

        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(TechType mode)
        {
            if (ModelState.IsValid)
            {
                db.TechTypes.Add(mode);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(mode);
        }

        public ActionResult Delete(int id = 0)
        {
            var mode = db.TechTypes.Find(id);
            if (mode == null)
            {
                return HttpNotFound();
            }
            return View(db.TechTypes.Find(id));
        }
        [HttpPost]
        [ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirm(int id = 0)
        {
            var mode = db.TechTypes.Find(id);
            db.TechTypes.Remove(mode);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

    }
}
